<!-- 工资详情 -->
<template>
  <div class="app-container">

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:post:export']"
        >导出</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="salaryList" @selection-change="handleSelectionChange">
<!--      <el-table-column type="selection" width="55" align="center" />-->
      <el-table-column label="姓名" align="center" prop="personName" />
      <el-table-column label="所属单位" align="center" prop="companyName" />
      <el-table-column label="身份证" align="center" prop="cardNum" />
      <el-table-column label="银行卡" align="center" prop="bankCard" />
      <el-table-column label="年份" align="center" prop="year" />
      <el-table-column label="月份" align="center" prop="month" />
      <el-table-column label="应发金额-元" align="center" prop="totalAmount" />
      <el-table-column label="应扣金额-元" align="center" prop="deductAmount" />
      <el-table-column label="实发金额-元" align="center" prop="realAmount" />
      <el-table-column label="欠发金额-元" align="center" prop="oweAmount" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:post:edit']"
          >编辑</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:post:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改岗位对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="700px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
         <el-row>
            <el-col :span="12">
                <el-form-item label="姓名" prop="personName">
                  <el-input v-model="form.personName" placeholder="" />
                </el-form-item>
            </el-col>
            <el-col :span="12">
               <el-form-item label="所属单位" prop="companyName">
                  <el-input v-model="form.companyName" placeholder="" />
                </el-form-item>
            </el-col>
         </el-row>
         <el-row>
            <el-col :span="12">
                <el-form-item label="身份证" prop="cardNum">
                  <el-input v-model="form.cardNum" placeholder="" />
                </el-form-item>
            </el-col>
            <el-col :span="12">
               <el-form-item label="银行卡号" prop="bankCard">
                <el-input v-model="form.bankCard" placeholder="" />
              </el-form-item>
            </el-col>
         </el-row>
         <el-row>
            <el-col :span="12">
                <el-form-item label="年份" prop="year">
                  <el-input v-model="form.year" placeholder="" />
                </el-form-item>
            </el-col>
            <el-col :span="12">
               <el-form-item label="月份" prop="month">
                <el-input v-model="form.month" placeholder="" />
              </el-form-item>
            </el-col>
         </el-row>
         <el-row>
            <el-col :span="12">
                <el-form-item label="应发金额-元" prop="totalAmount">
                  <el-input v-model="form.totalAmount" placeholder="" />
                </el-form-item>
            </el-col>
            <el-col :span="12">
               <el-form-item label="应扣金额-元" prop="deductAmount">
                  <el-input v-model="form.deductAmount" placeholder="" />
                </el-form-item>
            </el-col>
         </el-row>
        <el-row>
            <el-col :span="12">
                <el-form-item label="实发金额-元" prop="realAmount">
                  <el-input v-model="form.realAmount" placeholder="" />
                </el-form-item>
            </el-col>
            <el-col :span="12">
               <el-form-item label="欠发金额-元" prop="oweAmount">
                <el-input v-model="form.oweAmount" placeholder="欠发金额-元" />
              </el-form-item>
            </el-col>
         </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  

  </div>
</template>

<script>
import {detailList,exportDetail,editSave,deleteSalary} from "../../../api/system/salary";

export default {
  name: "Post",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 岗位表格数据
      salaryList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      inoutTable: false,
      // 状态数据字典
      statusOptions: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        companyName: this.$route.query.salary.companyName,
        year: this.$route.query.salary.year,
        month: this.$route.query.salary.month,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        personName: [
          { required: true, message: "姓名不能为空", trigger: "blur" }
        ],
        companyName: [
          { required: true, message: "所属单位不能为空", trigger: "blur" }
        ],
        cardNum: [
          { required: true, message: "身份证不能为空", trigger: "blur" }
        ],
        bankCard: [
          { required: true, message: "银行卡不能为空", trigger: "blur" }
        ],
        year: [
          { required: true, message: "年份不能为空", trigger: "blur" }
        ],
        month: [
          { required: true, message: "月份不能为空", trigger: "blur" }
        ],
        totalAmount: [
          { required: true, message: "应发金额不能为空", trigger: "blur" }
        ],
        deductAmount: [
          { required: true, message: "应扣金额不能为空", trigger: "blur" }
        ],
        realAmount: [
          { required: true, message: "实发金额不能为空", trigger: "blur" }
        ],
        oweAmount: [
          { required: true, message: "欠发金额不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询岗位列表 */
    getList() {
      this.loading = true;
      detailList(this.queryParams).then(response => {
        this.salaryList = response.data;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 岗位状态字典翻译
    statusFormat(row, column) {
      return this.selectDictLabel(this.statusOptions, row.status);
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        postId: undefined,
        postCode: undefined,
        postName: undefined,
        postSort: 0,
        status: "0",
        remark: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.postId)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      // this.reset();
      // const postId = row.postId || this.ids
      // getPost(postId).then(response => {
      //   this.form = response.data;
      //   this.open = true;
      //   this.title = "修改岗位";
      // });
      this.form=row;
      this.title = "修改当前单位 2020-2月 工资记录";
      this.open = true;
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          editSave(this.form).then(response => {
            if (response.code === 200) {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            }
          });
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const data={
        id :row.id
      };
      this.$confirm('是否确认删除'+row.personName+'的工资数据?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return deleteSalary(data);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(function() {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportDetail(queryParams);
        }).then(response => {
          this.download(response.msg);
        }).catch(function() {});
    }
  }
};
</script>
